<?php
class searchproductsMod extends commonMod {

	public function __construct()
	{
		parent::__construct();
	}
	
	public function index() {
		$itemno = trim($_POST["itemno"]);
		$gw = trim($_POST["gw"]);
		$material = trim($_POST["material"]);
		$size = trim($_POST["size"]);
		$packing = trim($_POST["packing"]);
		$cartonsize = trim($_POST["cartonsize"]);
		
		$where = '';
		
		if ($itemno != ''){
			$where .= " And C.itemno = "."'$itemno'";
		}
		
		if ($gw != ''){
			$where .= " And C.gw = "."'$gw'";
		}
		
		if ($material != ''){
			$where .= " And C.material = "."'$material'";
		}
		
		if ($size != ''){
			$where .= " And C.size = "."'$size'";
		}
		
		if ($packing != ''){
			$where .= " And C.packing = "."'$packing'";
		}
		
		if ($cartonsize != ''){
			$where .= " And C.cartonsize = "."'$cartonsize'";
		}
		
		$sql01 = 'SELECT cid FROM baiila_category A WHERE A.`show` = 1 AND A.pid IN (19) AND A.lang = 1 ORDER BY sequence ASC, cid ASC';
		$cids = $this->model->query($sql01,array(),true);
		
		$cids_a = array();
		
		foreach ($cids as $v){
			
			$cids_a[] = implode('', $v);
		}
		$cids_str = implode(',', $cids_a);
		$sql = 'SELECT C.*,A.*,B.name as cname,B.subname as csubname,B.mid FROM baiila_content A LEFT JOIN baiila_category B ON A.cid = B.cid LEFT JOIN baiila_expand_content_product C ON C.aid = A.aid WHERE A.status=1 AND B.cid in('.$cids_str.') AND A.image<>"" AND B.lang=1 '.$where.' ORDER BY A.sequence asc LIMIT 100 ';		
		$info = $this->model->query($sql,array(),true);
		//echo $this->model->getSql();
		echo json_encode($info);exit();
		
	}
	
	
	
	
}